package com.zlx.service;

import com.zlx.dao.MeetingDao;
import com.zlx.entities.Meeting;
import com.zlx.entities.User;
import com.zlx.enums.StatusEnum;
import com.zlx.utils.Page;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @Author 周罗校
 * @Description
 * @ClassName MeetingService
 * @date 2020.09.25 10:55:32
 * 该版权归周罗校所有，最终解释权以官方为准
 */
public class MeetingService {
    private MeetingDao meetingDao = new MeetingDao();

    /**
     * @Author 周罗校
     * @Description 会议列表
     * @Param []
     * @return java.util.List<com.zlx.entities.Meeting>
     * @Date 2020.09.25 12:27:24
     **/
    public List<Meeting> listAll(Page<Meeting> page, String name){
        List<Meeting> list = meetingDao.listAll(page,name);
        return list;
    }
    /**
     * @Author 周罗校
     * @Description 会议记录数
     * @Param [name]
     * @return java.lang.Integer
     * @Date 2020.09.25 12:27:48
     **/
    public Integer getMeetCount(String name){
        return meetingDao.getMeetCount(name);
    }
    /**
     * @Author 周罗校
     * @Description 插入会议数据
     * @Param [meeting]
     * @return void
     * @Date 2020.09.25 17:04:06
     **/
    public void InsertMeeting(Meeting meeting){
//        System.out.println(meeting.getEndTime());

        String end = meeting.getEndTime().replace("T", " ");
        String start = meeting.getStartTime().replace("T", " ");
//        System.out.println(replace);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        try {
            Date endTime = simpleDateFormat.parse(end);
            Date startTime = simpleDateFormat.parse(start);
            if (endTime.getTime()<new Date().getTime()){
                //会议结束
                meeting.setStatus(StatusEnum.END.getValue());
            }else if(startTime.getTime()>new Date().getTime()){
                //会议未开始
                meeting.setStatus(StatusEnum.NO_START.getValue());
            }else if(startTime.getTime()<new Date().getTime()&&endTime.getTime()>new Date().getTime()){
                //会议进行中
                meeting.setStatus(StatusEnum.BENGING.getValue());
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        meetingDao.InsertMeeting(meeting);
    }
    /**
     * @Author 周罗校
     * @Description 更新会议状态
     * @Param [status, id]
     * @return void
     * @Date 2020.09.26 10:09:00
     **/
    public void updateStatusById(Integer status,Integer id){
        meetingDao.updateStatusById(status,id);
    }
    /**
     * @Author 周罗校
     * @Description 更新所有信息去更新时间
     * @Param []
     * @return java.util.List<com.zlx.entities.Meeting>
     * @Date 2020.09.26 10:19:49
     **/
    public List<Meeting> getAllInfoRToUpdateStatus(){
        List<Meeting> allInfoRToUpdateStatus = meetingDao.getAllInfoRToUpdateStatus();
        return allInfoRToUpdateStatus;
    }
    /**
     * @Author 周罗校
     * @Description 根据id获取会议详情
     * @Param [id]
     * @return com.zlx.entities.Meeting
     * @Date 2020.09.26 11:05:00
     **/
    public Meeting getMeetingInfoById(Integer id){
        return meetingDao.getMeetingInfoById(id);
    }
    /**
     * @Author 周罗校
     * @Description 参加会议
     * @Param [uid=用户id, mid=会议id]
     * @return void
     * @Date 2020.09.26 12:06:08
     **/
    public void insertJoinMeetingInfo(Integer uid,Integer mid){
        meetingDao.insertJoinMeetingInfo(uid,mid);
    }
    /**
     * @Author 周罗校
     * @Description 获取当前用户是参加了会议
     * @Param [uid, mid]
     * @return java.lang.Integer
     * @Date 2020.09.26 14:36:02
     **/
    public Integer getJoinMeeting(Integer uid,Integer mid){
        return meetingDao.getJoin(uid,mid);
    }
    /**
     * @Author 周罗校
     * @Description 取消参加会议
     * @Param [uid, mid]
     * @return java.lang.Integer
     * @Date 2020.09.26 14:51:26
     **/
    public void deleteJoinMeeting(Integer uid,Integer mid){
        meetingDao.deleteJoinMeeting(uid,mid);
    }
    /**
     * @Author 周罗校
     * @Description 获取实际参与会议的人数
     * @Param [mid]
     * @return java.lang.Integer
     * @Date 2020.09.26 15:17:39
     **/
    public Integer getJoinMeetinngCount(Integer mid){
        return meetingDao.getJoinMeetinngCount(mid);
    }
    /**
     * @Author 周罗校
     * @Description 根据id删除会议
     * @Param [id]
     * @return void
     * @Date 2020.09.26 15:42:45
     **/
    public void deleteMeetinngById(Integer id){
        meetingDao.deleteMeetinngById(id);
    }
}
